﻿using System;
using System.Collections.Generic;

namespace EasySL.Core
{
    public abstract class TaskBase
    {
        public event EventHandler<EventArgs> BeforeStart;

        public void Start(TaskManager taskManager, object state)
        {
            this._taskManager = taskManager;

            if (this.BeforeStart != null)
            {
                this.BeforeStart(this, null);
            }

            this.RunProc(state);
        }

        public void Start(object state)
        {
            this.Start(null, state);
        }

        public void Start()
        {
            this.Start(null, null);
        }

        protected void RunFinished()
        {
            if (this._taskManager != null)
            {
                this._taskManager.Next();
            }
        }

        protected abstract void RunProc(object state);

        private TaskManager _taskManager = null;
    }

    

}
